package com.cnap.multiclouldmgmt.controller;

import com.cnap.multiclouldmgmt.MulticlouldmgmtApplicationTests;
import com.cnap.multiclouldmgmt.model.scale.QueryScalingConfigParam;
import com.cnap.multiclouldmgmt.model.scale.ScalingConfigDTO;
import com.cnap.multiclouldmgmt.model.scale.group.QueryScalingGroupParam;
import com.cnap.multiclouldmgmt.model.scale.group.ScalingGroupDTO;
import com.cnap.multiclouldmgmt.model.scale.policy.ScalingPolicyDTO;
import com.cnap.multiclouldmgmt.service.ScalingService;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.mock.mockito.MockBean;

import java.util.ArrayList;
import java.util.List;

/**
 * <类文件描述>
 *
 * @author xc
 **/
class ScalingControllerTest extends MulticlouldmgmtApplicationTests {

    @Autowired
    private ScalingController scalingController;
    @MockBean
    private ScalingService scalingService;

    @Test
    void getScalingGroup() {
        QueryScalingGroupParam param = new QueryScalingGroupParam();
        Mockito.when(scalingService.findByPage(param)).thenReturn(null);

        Assertions.assertDoesNotThrow(()->{
            scalingController.getScalingGroup(param);
        });
    }

    @Test
    void createScalingGroup() {
        ScalingGroupDTO dto = new ScalingGroupDTO();
        Mockito.when(scalingService.createScalingGroup(dto)).thenReturn(true);

        Assertions.assertDoesNotThrow(()->{});
        scalingController.createScalingGroup(dto);
    }

    @Test
    void createScalingPolicy() {
        List<ScalingPolicyDTO> dtos = new ArrayList<>();
        Mockito.when(scalingService.createScalingPolicy(dtos)).thenReturn(true);

        Assertions.assertDoesNotThrow(()->{
            scalingController.createScalingPolicy(dtos);
        });
    }

    @Test
    void testGetScalingGroup() {
        QueryScalingConfigParam param = new QueryScalingConfigParam();
        Mockito.when(scalingService.findByPage(param)).thenReturn(null);

        Assertions.assertDoesNotThrow(()->{
            scalingController.getScalingGroup(param);
        });
    }

    @Test
    void createScalingConfig() {
        ScalingConfigDTO dto = new ScalingConfigDTO();
        Mockito.when(scalingService.createScalingConfig(dto)).thenReturn(true);

        Assertions.assertDoesNotThrow(()->{
            scalingController.createScalingConfig(dto);
        });
    }

    @Test
    void startScalingPolicy() {
        Mockito.when(scalingService.startScale("gpId")).thenReturn(true);

        Assertions.assertDoesNotThrow(()->{
            scalingController.startScalingPolicy("gpId");
        });
    }

    @Test
    void stopScalingPolicy() {
        Mockito.when(scalingService.stopScale("gpId")).thenReturn(true);

        Assertions.assertDoesNotThrow(()->{
            scalingController.stopScalingPolicy("gpId");
        });
    }

    @Test
    void deleteScalingPolicy() {
        Mockito.when(scalingService.deleteScalingGroup("gpId", true)).thenReturn(true);

        Assertions.assertDoesNotThrow(()->{
            scalingController.deleteScalingPolicy("gpId");
        });
    }

    @Test
    void deleteScalingConfig() {
        Mockito.when(scalingService.deleteScalingConfigById("id")).thenReturn(true);

        Assertions.assertDoesNotThrow(()->{
            scalingController.deleteScalingConfig("id");
        });
    }

    @Test
    void getAllResources() {
        Mockito.when(scalingService.getAllCloudResources()).thenReturn(null);

        Assertions.assertDoesNotThrow(()->{
            scalingController.getAllResources();
        });
    }

    @Test
    void getResourceById() {
        Mockito.when(scalingService.getCloudResourceById("resId")).thenReturn(null);
        Assertions.assertDoesNotThrow(()->{
            scalingController.getResourceById("resId");
        });
    }
}